package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import java.awt.Rectangle;
import java.awt.ScrollPane;

import javax.swing.*;

import java.awt.Dimension;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.HashMap;


import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;

import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import code.Language;
import code.Settings;

public class ATOCOmain extends JFrame {

	Color c= new Color(0x80, 0x80, 0xFF);  //  @jve:decl-index=0:

	Color topic = new Color(0, 0, 100);

	Color area = new Color(238, 238, 238);

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JSplitPane jSplitPane = null;

	private JPanel jPanel = null;

	private JSplitPane jSplitPane1 = null;

	private JPanel jPanel1 = null;

	private JPanel jPanel2 = null;

	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JLabel jLabel5 = null;
	private JLabel jLabel6 = null;

	private JLabel jLabel10 = null;
	private JLabel jLabel11 = null;
	private JLabel jLabel111 = null;
	private JLabel jLabel112 = null;
	private JLabel jLabel113 = null;
	private JLabel jLabel114 = null;
	private JLabel jLabel115 = null;  //  @jve:decl-index=0:visual-constraint="10,212"
	private JLabel jLabel116 = null;

	private JLabel jLabelsettings = null;
	private JLabel jLabelpassword = null;
	private JLabel jLabelkey = null;
	private JLabel jLabelinteg = null;
	private JLabel jLabeldigitalsig = null;
	private JLabel jLabelcert = null;
	private JLabel jLabelencdec = null;

	private JLabel jLabelinfo = null;

	JTextArea panel3area = null;
	Border empty = new EmptyBorder(0,0,0,0);
	JScrollPane panel3scroll = null;
	JScrollPane mainscroll = null;
	JScrollPane operationscroll = null;

	private HashMap labels;

	JLabel jLabelnote;
	private Settings s;

	private JPanel listPane = null;

	private JLabel deleteLabel = null;

	private JLabel saveLabel = null;

	public ATOCOmain() {
		super();
		s = new Settings();
		s.initiate();
		Language l = new Language();
		labels = l.changeLanguage((String) s.global.get("language"), "ATOCOmain", (String) s.global.get("installPath"));
		initialize(new MainPanel());
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setUndecorated(true);
		this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
		this.setVisible(true);
	}

	public void changeLanguage(){
		System.out.println("ATOCOmaindeki global language: "+s.global.get("language"));
		Language l = new Language();
		labels = l.changeLanguage((String) s.global.get("language"), "ATOCOmain", (String) s.global.get("installPath"));
		System.out.println(labels);

	}


	private void initialize(JPanel jPanel) {
		this.setSize(1180, 680);
		this.setContentPane(getJContentPane(jPanel));

	}


	private JPanel getJContentPane(JPanel jPanel) {
		this.setTitle((String) labels.get("title"));
		jContentPane = new JPanel();
		jContentPane.setLayout(new BorderLayout());
		jContentPane.add(getJSplitPane(jPanel), BorderLayout.CENTER);

		return jContentPane;
	}


	private JSplitPane getJSplitPane(JPanel jPanel) {

		jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		operationscroll = new JScrollPane(getJPanel());
		operationscroll.setBorder(empty);
		operationscroll.setMinimumSize(new Dimension(310, 100));

		jSplitPane.setLeftComponent(operationscroll);

		jSplitPane.setRightComponent(getJSplitPane1(jPanel));
		jSplitPane.setResizeWeight(0.4D);


		return jSplitPane;
	}

	public void createPanel3()
	{
		jPanel2 = new JPanel();
		jPanel2.setLayout( new BorderLayout() );
		jPanel2.setPreferredSize( new Dimension( 400, 100 ) );
		//jPanel2.setMinimumSize( new Dimension( 100, 50 ) );
		jPanel2.setMinimumSize( new Dimension( 100, 100 ) );
		panel3area = new JTextArea();
		panel3scroll = new JScrollPane(panel3area);
		panel3scroll.setBorder(empty);
		jLabelnote = new JLabel((String)labels.get("jLabelnote"));
		jPanel2.add( jLabelnote , BorderLayout.NORTH );
		jPanel2.add( panel3scroll, BorderLayout.CENTER );
		//jPanel2.add(new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/saveicon.gif")), BorderLayout.WEST);	
		listPane  = new JPanel();
		listPane.setLayout(new BoxLayout(listPane, BoxLayout.Y_AXIS));
		saveLabel  = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/saveicon.gif"));
		saveLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {

				try {
					if(panel3area.getText().isEmpty()){

						JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
								"Text Area is Empty !!");
					}else{
						String inputText = JOptionPane.showInputDialog("Enter the File Name: ( ex : ATOCO ) ");
						String path =((String) s.global.get("filelocation"))
						+ File.separatorChar + inputText + ".txt";
						FileOutputStream os = new FileOutputStream(path);
						DataOutputStream dout = new DataOutputStream(os);
						String st = panel3area.getText();
						System.out.println(st);
						dout.writeBytes(st);
						dout.close();

						JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
								"File Name: " + inputText + "\n" +
								"File Path: " + path);
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		listPane.add(saveLabel);
		deleteLabel  = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/delete.gif"));
		deleteLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				panel3area.setText("");
			}
		});
		listPane.add(deleteLabel);
		jPanel2.add(listPane, BorderLayout.WEST);
	}


	private JPanel getJPanel() {

		jPanel = new JPanel();
		jPanel.setLayout(null);

		jPanel.setBackground(Color.WHITE);

		jPanel.setPreferredSize( new Dimension( 0, 640 ) );
		//jPanel2.setMinimumSize( new Dimension( 100, 50 ) );


		ImageIcon settings = new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/settings.jpg");
		jLabel116 = new JLabel(settings);
		jLabel116.setBounds(new Rectangle(30, 448, 50, 50));
		//jLabel116.setText((String)labels.get("jLabel116"));
		//jLabel116.setForeground(c);
		//jLabel116.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
		jLabel115 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/password2.jpg"));
		jLabel115.setBounds(new Rectangle(30, 389, 50, 50));
		//jLabel115.setText((String)labels.get("jLabel115"));
		//jLabel115.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
		//jLabel115.setForeground(c);
		jLabel115.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new StrongPasswordMain(atocoframe()));
			}
		});

		jLabel114 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/key.jpg"));
		jLabel114.setBounds(new Rectangle(30, 329, 50, 50));
//		jLabel114.setText((String)labels.get("jLabel114"));
//		jLabel114.setForeground(c);
//		jLabel114.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
		jLabel114.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new KeyManagementMain(atocoframe()));
			}
		});
		jLabel113 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/integrity.jpg"));
		jLabel113.setBounds(new Rectangle(30, 265, 50, 50));
//		jLabel113.setText((String)labels.get("jLabel113"));
//		jLabel113.setForeground(c);
//		jLabel113.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
		jLabel113.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new DataIntegrityMain(atocoframe()));
			}
		});
		jLabel112 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/authen.JPG"));
		jLabel112.setBounds(new Rectangle(30, 205, 50, 50));
//		jLabel112.setText((String)labels.get("jLabel112"));
//		jLabel112.setForeground(c);
//		jLabel112.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
		jLabel112.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new DigitalSignatureMain(atocoframe()));
			}
		});
		jLabel111 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/certif.jpg"));
		jLabel111.setBounds(new Rectangle(30, 144, 50, 50));
//		jLabel111.setText((String)labels.get("jLabel111"));
//		jLabel111.setForeground(c);
//		jLabel111.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
//		jLabel111.setHorizontalTextPosition(SwingConstants.RIGHT);
		jLabel111.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new CertificateMain(atocoframe()));
			}
		});
		jLabel11 = new JLabel(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/encdeclast.jpg"));
		jLabel11.setBounds(new Rectangle(30, 83, 50, 50));
//		jLabel11.setText((String)labels.get("jLabel11"));
//		jLabel11.setForeground(c);
//		jLabel11.setHorizontalTextPosition(SwingConstants.RIGHT);
//		jLabel11.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
		jLabel11.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new EncryptionType(atocoframe()));
			}
		});
		jLabel10 = new JLabel();
		jLabel10.setBounds(new Rectangle(50, 30, 210, 35));
		jLabel10.setText((String)labels.get("jLabel10"));
		jLabel10.setForeground(topic);
		jLabel10.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
		jLabel6 = new JLabel();
		jLabel6.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel6.setBounds(new Rectangle(5, 460, 25, 25));
		jLabel6.setText("");
		jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel6");
				contentPane(new OperationHelp(atocoframe(), "Settings"));
			}
		});
		jLabel5 = new JLabel();
		jLabel5.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel5.setBounds(new Rectangle(5, 400, 25, 25));
		jLabel5.setText("");
		jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel5");
				contentPane(new OperationHelp(atocoframe(), "StrongPassword"));
			}
		});
		jLabel4 = new JLabel();
		jLabel4.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel4.setBounds(new Rectangle(5, 340, 25, 25));
		jLabel4.setText("");
		jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel4");
				contentPane(new OperationHelp(atocoframe(), "KeyStore"));
			}
		});
		jLabel3 = new JLabel();
		jLabel3.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel3.setBounds(new Rectangle(5, 280, 25, 25));
		jLabel3.setText("");
		jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel3");
				contentPane(new OperationHelp(atocoframe(), "DataIntegrity"));
			}
		});
		jLabel2 = new JLabel();
		jLabel2.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel2.setBounds(new Rectangle(5, 220, 25, 25));
		jLabel2.setText("");
		jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel2");
				contentPane(new OperationHelp(atocoframe(), "DigitalSignature"));
			}
		});
		jLabel1 = new JLabel();
		jLabel1.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel1.setBounds(new Rectangle(5, 160, 25, 25));
		jLabel1.setText("");
		jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel1");
				contentPane(new OperationHelp(atocoframe(), "Certificate"));
			}
		});
		jLabel = new JLabel();
		jLabel.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/questionmark.jpg"));
		jLabel.setBounds(new Rectangle(5, 100, 25, 25));
		jLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				System.out.println("jLabel");
				contentPane(new OperationHelp(atocoframe(), "Enc/Dec"));
			}
		});

		jLabelinfo = new JLabel((String) labels.get("jLabelinfo"));
		jLabelinfo.setIcon(new ImageIcon((String) s.global.get("installPath") + File.separator + "images/en/wall.gif"));
		jLabelinfo.setForeground(Color.GRAY);
		jLabelinfo.setFont(new Font("Arial", Font.ITALIC, 11));
		jLabelinfo.setBounds(new Rectangle(10, 550, 250, 50));

		jLabelsettings = new JLabel();
		jLabelsettings.setText((String)labels.get("jLabelsettings"));
		jLabelsettings.setBounds(new Rectangle(90, 448, 200, 50));
		jLabelsettings.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new SettingsMain(atocoframe()));
			}
		});
		jLabelpassword = new JLabel();
		jLabelpassword.setText((String)labels.get("jLabelpassword"));
		jLabelpassword.setBounds(new Rectangle(90, 389, 200, 50));
		jLabelpassword.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new StrongPasswordMain(atocoframe()));
			}
		});
		jLabelkey = new JLabel();
		jLabelkey.setText((String)labels.get("jLabelkey"));
		jLabelkey.setBounds(new Rectangle(90, 329, 200, 50));
		jLabelkey.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new KeyManagementMain(atocoframe()));
			}
		});
		jLabelinteg = new JLabel();
		jLabelinteg.setText((String)labels.get("jLabelinteg"));
		jLabelinteg.setBounds(new Rectangle(90, 265, 200, 50));
		jLabelinteg.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new DataIntegrityMain(atocoframe()));
			}
		});
		jLabeldigitalsig = new JLabel();
		jLabeldigitalsig.setText((String)labels.get("jLabeldigitalsig"));
		jLabeldigitalsig.setBounds(new Rectangle(90, 205, 200, 50));
		jLabeldigitalsig.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new DigitalSignatureMain(atocoframe()));
			}
		});
		jLabelcert = new JLabel();
		jLabelcert.setText((String)labels.get("jLabelcert"));
		jLabelcert.setBounds(new Rectangle(90, 144, 200, 50));
		jLabelcert.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new CertificateMain(atocoframe()));
			}
		});
		jLabelencdec = new JLabel();
		jLabelencdec.setText((String)labels.get("jLabelencdec"));
		jLabelencdec.setBounds(new Rectangle(90, 83, 200, 50));
		jLabelencdec.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				contentPane(new EncryptionType(atocoframe()));

			}
		});

		jPanel.setSize(317, 437);
		jPanel.add(jLabel, null);
		jPanel.add(jLabel1, null);
		jPanel.add(jLabel2, null);
		jPanel.add(jLabel3, null);
		jPanel.add(jLabel4, null);
		jPanel.add(jLabel5, null);
		jPanel.add(jLabel6, null);
		jPanel.add(jLabel10, null);
		jPanel.add(jLabel11, null);
		jPanel.add(jLabel111, null);
		jPanel.add(jLabel112, null);
		jPanel.add(jLabel113, null);
		jPanel.add(jLabel114, null);
		jPanel.add(jLabel115, null);
		jPanel.add(jLabel116, null);

		jPanel.add(jLabelsettings, null);
		jPanel.add(jLabelpassword, null);
		jPanel.add(jLabelkey, null);
		jPanel.add(jLabelinteg, null);
		jPanel.add(jLabeldigitalsig, null);
		jPanel.add(jLabelcert, null);
		jPanel.add(jLabelencdec, null);

		jPanel.add(jLabelinfo, null);


		return jPanel;
	}

	private ATOCOmain atocoframe(){
		return this;
	}
	public void reinitialize(JPanel jPanel){
		initialize(jPanel);
	}

	public void contentPane(JPanel jPanel)
	{
		this.setContentPane(getJContentPane(jPanel));
		this.validate();
		//this.setContentPane(getJContentPane(jPanel));
	}
	private JSplitPane getJSplitPane1(JPanel jPanel) {
		jPanel1= jPanel;
//		JScrollPane scrollpanel1 = new JScrollPane();
//		jPanel1.add(scrollpanel1);
//		jPanel1.setPreferredSize( new Dimension( 400, 700 ));
		System.out.println(jPanel);
		jSplitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jPanel1, getJPanel2());
		mainscroll = new JScrollPane(jPanel1);
		mainscroll.setBorder(empty);
		mainscroll.setMinimumSize(new Dimension(850, 100));
		jSplitPane1.setLeftComponent(mainscroll);
		jSplitPane1.setRightComponent(getJPanel2());
		jSplitPane1.setResizeWeight(1D);




		return jSplitPane1;
	}

	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setLayout(new BorderLayout());
			createPanel3();
		}
		return jPanel2;
	}
	public static void main(String args[]){
		ATOCOmain a= new ATOCOmain();
	}


}  //  @jve:decl-index=0:visual-constraint="10,10"
